﻿CREATE TABLE Tovar
(	
	ID_tovar	INT IDENTITY(1,1) NOT NULL,
	photo		NVARCHAR(MAX)	  NULL,
	nameTovar	NVARCHAR(100)	  NOT NULL,
	vendor		NVARCHAR(100)	  NOT NULL,
	price		INT				  NOT NULL,
	discount	INT				  NULL,
	countTovar  INT				  NOT NULL,

	CONSTRAINT PK_Tovar PRIMARY KEY (ID_tovar)
);

CREATE TABLE Station
(
	ID_station	INT IDENTITY(1,1) NOT NULL,
	addressSt	NVARCHAR(100)	  NOT NULL,

	CONSTRAINT PK_Station PRIMARY KEY (ID_station)
);

CREATE TABLE Orders
(
	ID_order	INT IDENTITY(1,1) NOT NULL,
	ID_station	INT				  NOT NULL,
	statusOrd	NVARCHAR(10)	  NOT NULL,
	dateOrd		DATETIME		  NOT NULL,
	countOrd	INT				  NOT NULL,

	CONSTRAINT PK_Orders PRIMARY KEY (ID_order),

	CONSTRAINT FK_Station FOREIGN KEY (ID_station)
	REFERENCES Station (ID_station)
);

CREATE TABLE TovarsToOrder
(
	ID_tovarsToOrder	INT IDENTITY(1,1) NOT NULL,
	ID_tovar			INT				  NOT NULL,
	ID_order			INT				  NOT NULL,

	CONSTRAINT PK_TovarsToOrder PRIMARY KEY (ID_tovarsToOrder),

	CONSTRAINT FK1_TovarsToOrder FOREIGN KEY (ID_tovar)
	REFERENCES Tovar (ID_tovar),

	CONSTRAINT FK2_TovarsToOrder FOREIGN KEY (ID_order)
	REFERENCES Orders (ID_order)
);

CREATE TABLE Admins
(
	ID_admin	INT IDENTITY(1,1) NOT NULL,
	loginAdmin	NVARCHAR(80)	  NOT NULL,
	passAdmin	NVARCHAR(100)	  NOT NULL,

	CONSTRAINT PK_Admins PRIMARY KEY (ID_admin)
);

INSERT INTO Station(addressSt)
VALUES (N'ул. Пушкинская, д. 9'),
	   (N'ул. Октябрьская, д. 33');